@echo off
REM 完整的编码解决方案
REM 设置控制台代码页为UTF-8
chcp 65001 >nul 2>&1
REM 设置Python环境变量
set PYTHONIOENCODING=utf-8
set PYTHONUTF8=1
echo ============================================
echo DXF镜像工具 - 运行脚本
echo DXF Mirror Tool - Run Script
echo ============================================
echo.

REM 检查Python是否已安装
python --version >nul 2>&1
if errorlevel 1 (
    echo 错误：未检测到Python，请先运行 install_dependencies.bat 安装依赖
    echo Error: Python not detected, please run install_dependencies.bat first
    goto end
)

REM 检查main.py是否存在
if not exist "main.py" (
    echo 错误：未找到main.py文件
    echo Error: main.py file not found
    goto end
)

echo 正在运行DXF镜像工具...
echo Running DXF Mirror Tool...
echo.

REM 运行主程序
echo 使用示例 / Usage examples:
echo   python main.py [输入文件夹路径] / python main.py [input_folder_path]
echo   python main.py ./test_folder
echo   python main.py "C:\path\to\dxf\files"
echo.
echo 如果不提供参数，将使用当前目录作为输入文件夹
echo If no arguments provided, current directory will be used as input folder
echo.

REM 检查是否提供了命令行参数
if "%~1"=="" (
    echo 使用当前目录作为输入文件夹...
    echo Using current directory as input folder...
    python main.py .
) else (
    echo 使用指定文件夹: %1
    echo Using specified folder: %1
    python main.py "%~1"
)

echo.
echo ============================================
echo 程序运行完成！
echo Program execution completed!
echo ============================================
echo.

REM 检查程序退出状态
if errorlevel 1 (
    echo 程序运行过程中出现错误，错误代码: %errorlevel%
    echo Program encountered an error, error code: %errorlevel%
) else (
    echo 程序运行成功！
    echo Program ran successfully!
)

:end
echo.
echo 按任意键退出...
echo Press any key to exit...
pause >nul